﻿#pragma once

#include "CIndexWrapper.h"
#include "CTickmarkManager.h"
#include "CBuffer10Wrapper.h"
#include "CEventManager.h"
#include "CResInfWrapper.h"

class AnalExecutor;
class CResultCaculator
{
public:
    LPVOID head;                         // x0 -> 0
    TDLLResultListItem *pTDLLItem;       // x1 -> 4
    CIndexWrapper *pIndexWrapper;        // x2 -> 8
    CTickmarkManager *pCTickmarkManager; // x3 -> 12
    CBuffer10Wrapper *pBuffer10Wrapper;  // x4 -> 16
    CEventManager *pEventManager;        // x5 -> 20
    CResInfWrapper *pResInfWrapper;      // x6 -> 24
    AnalInfo *pAnalInfo;                 // x7 -> 28
    int32_t *pRawBagBuffer;              // x8 -> 32
    AnalExecutor *pAnalExecutor;         // x9 -> 36
    int32_t untreatedNum;                // x10 -> 40
    int32_t baseIdx;                     // x11 -> 44
    int32_t finishFlag;                  // x12 -> 48
    int32_t typeCodeStatus;              // x13 -> 52
    int32_t tickmarkStatus;              // x14 -> 56
    int32_t storedTE;                    // x15 -> 60
    int32_t topBottomHS;                 // x16 -> 64
    int32_t smoothAreaShift;             // x17 -> 68
    TDLLResultListItem *pCalcItem;       // x18 -> 72
    int32_t x19;                         // x19 -> 76
    double tempSlope;                    // x20,21 -> 80,84
    double tempArea;                     // x22 -> 88,92
    float tempTime;                      // x24 -> 96
    float tempHeight;                    // x25 -> 100
    double xMinUnitK;                    // x26 -> 104

    CResultCaculator();

    void printSelf(char *captionUpper, int32_t deep);

    // sub_100036B8
    CResultCaculator *init(CTickmarkManager *pTickmarkManager, CBuffer10Wrapper *pBuffer10Wrapper,
                           CEventManager *pEventManager, CResInfWrapper *pResInf, AnalInfo *pAnalInfo,
                           int32_t *pRawBag, AnalExecutor *pX);

    CResultCaculator *init_();

    // sub_1001B220
    void *close(char flag);

    // sub_1001B250
    void *close();

    // sub_1001B2E0
    CResultCaculator *clean();

    // sub_10003796
    CResultCaculator *initData();

    // sub_1001A170
    CResultCaculator *clean_();

    // 10003B09
    int32_t checkResInfoNum(int32_t num);

    // sub_1001B9F0
    int32_t isLocalDiffHExtruded1D();

    // sub_100083BB
    void setPeakStart(int32_t time, int32_t height, double area);

    // sub_10008374
    void setPeakEnd(int32_t time, int32_t height, double area);

    // sub_1001A450
    int32_t processIndexAndTickmark(int32_t offset);

    // unknown_libname_4
    int32_t getTickmarkStatus();

    // sub_100052C0
    int32_t setIndex1AndTickmark(int32_t offset);

    // sub_10005D8D
    int32_t finishBatchHandle(int32_t offset);

    // sub_10003B09
    int32_t isOffsetOutBound(int32_t offset);

    // sub_10003AB5
    int32_t isOffsetOutBoundV2(int32_t offset);

    // sub_10005602
    int32_t setIndex1EndResult(int32_t offset);

    // sub_1000676F
    void setSOL_TICK();

    // sub_1000595D
    int32_t setTanStopAndIncIndexBuf2(int32_t offset);

    // sub_10003DCA
    int32_t isAreaShiftPositive(int32_t offset, int32_t flag);

    // sub_1001A1E0
    int32_t getBaseTailTangant();

    // sub_10003CA9
    float calcAreaDiffShift(int32_t offset, int32_t flag);

    // sub_100088EC
    int32_t calcResultAndSetBaseIdx();

    // sub_10008A2D
    int32_t calcResultValue(int32_t offet, float freq);

    // sub_10003F8A
    void calcAreaTimeHeight(int32_t *rbagBuffer);

    // sub_1001A2A0
    int32_t isTrEqualTsV0(int32_t idx);

    // sub_1001A240
    int32_t isTrEqualTeV0(int32_t idx);

    // sub_1000874E
    void setHeightValues(int32_t *rbagBuffer);

    // sub_100091B1
    int32_t calcResultUntilTailReached(TDLLResultListItem *pRes, int32_t tail, float freq, int32_t offset,
                                       int32_t flag);

    // sub_1000B02B
    double calcResultEndValue1(TDLLResultListItem *pRes, int32_t head, int32_t tail, int32_t idx, float hs, float fts,
                               int32_t *idxArray, int32_t offset);

    // sub_1000AE05
    int32_t calcResultEndValue0(TDLLResultListItem *pRes, int32_t head, int32_t tail, int32_t idx0, int32_t idx1);

    // sub_10009D44
    int32_t calcResultItemValue(int32_t head, int32_t offset, float fts, float hs, float slope, float freq);

    // sub_10004F5E
    void calcTypeCode(int32_t offset);

    // sub_1000462F
    int32_t finishEndValueAccordingBuffer10(int32_t buffNo, int32_t tail, int32_t offset);

    // sub_100044FE
    int32_t checkTailReached(int32_t offset);

    // sub_1001A300
    int32_t isIndex1Valid_();

    // sub_1001A490
    int32_t isTHValueInitialized(int32_t idx);

    // sub_1001B300
    int32_t isDriftOrSlopeExceedDeltaH();

    // sub_1001B360
    int32_t isEventDriftExceed();

    // sub_10008058
    int32_t isScaledSlopeExceed(int32_t scale);

    // sub_10003A52
    int32_t isSlopeX10Exceed(int32_t offset);

    // sub_1000382C
    double getDeltaHr(int32_t offset);

    // sub_10003C55
    int32_t goPrevAfterClear();

    // sub_1000AA11
    int32_t calcResultNotC86(int32_t head, int32_t tail);

    // sub_1000A64C
    void setIndexBufUntil(int32_t tail);

    // sub_10005A76
    int32_t setIndexBuf1Head(int32_t head, int32_t flag);

    // sub_10005C6A
    int32_t setIndexBuf2Head(int32_t head, int32_t flag);

    // sub_10005D19
    int32_t setIndexBuf2Tail(int32_t tail, int32_t flag);

    // sub_10005BB4
    int32_t setIndexBuf1Tail(int32_t tail, int32_t flag);

    // sub_1000B2DA
    int32_t calcIndex1ResultEndValue();

    // sub_1001B4F0
    int32_t setMinimumHS(int32_t *hsMin);

    // sub_1001AAF0
    CResultCaculator *setBaseTailTangant(int32_t baseTail);

    // sub_10003B57
    int32_t movePointerNext();

    // sub_10003F11
    CResultCaculator *setStartFromBuffer10(int32_t buffNo, int32_t offset);

    // sub_10004EE2
    int32_t setStartAsPrevEnd();

    // sub_1000518A
    int32_t setFirstApexTick(int32_t offset);

    // sub_100053F9
    int32_t isIndexBuf1EqualHead(int32_t offset);

    // sub_10005838
    int32_t setPeakTB(int32_t offset);

    // sub_10005E62
    void setTickmarkGoPrev(int32_t idx);

    // sub_1000610C
    void setTickmarkRecursively(int32_t idx);

    // sub_10006326
    int32_t setTickmarkRecursivelyV2(int32_t tail);

    // sub_10006A23
    void setAlternateRES();

    // sub_10006B22
    int32_t setAlternateERS();

    // sub_10006C1B
    int32_t searchIndexAndCalcValueEX();

    // sub_1001A5F0
    int32_t isHeadPointBeginning();

    // sub_10004AA4
    int32_t calcCurrentPrevAreaTimeHeight(int32_t topOrBottom);

    // sub_10008316
    double findAndCalcPeakVaue();

    // sub_10006DA1
    double findAndCalcPeakVaueV2();

    // sub_10004880
    double calcPeakVaue(int32_t buffNo, int32_t offset);

    // sub_10007094
    void setCurrenPeakValue();

    // sub_1000737A
    int32_t setEndValueIfDownSlopeMoreSharp();

    // sub_1001A620
    int32_t isTail2Zero();

    // sub_1001A6D0
    double getDiffFte0AndTr2(int32_t idx);

    // sub_1001A7F0
    double getDiffTr2AndFts2();

    // sub_1001A720
    double getDiffTr0(double tr, int32_t offset);

    // sub_1001A750
    double getDiffTr0AndFts0(int32_t offset);

    // sub_1001A660
    double getDiffFte0AndFte1(int32_t offset);

    // sub_10007584
    int32_t isEventSlopeExceed();

    // sub_10007689
    int32_t isHeightNormal();

    // sub_1001A8F0
    int32_t exceedHalfFirstHR(int32_t offset);

    // sub_100077B0
    int32_t isCurrentPeakHeightExceed();

    // sub_10007992
    int32_t lessThenEventDrift();

    // sub_10007E74
    int32_t checkSlopeIsExceed(int32_t time);

    // sub_10008180
    void setSolTickOrIndex2Flag();

    // sub_100081DC
    int32_t restoreEndValueFromBuffer10();

    // sub_100083F8
    void saveTempValue();

    // sub_10008579
    int32_t restoreTempEndValue(int32_t idx);

    // sub_1000AC2D
    int32_t isDownSlopeExceedEvDrift(int32_t idx);

    // sub_1001A360
    int32_t isIndexPositive();

    // sub_1001A380
    int32_t isTrEqualTeV1(int32_t offset);

    // sub_1001A430
    int32_t isIndex2Valid_();

    // sub_1001A880
    int32_t isTrEqualTsV1(int32_t offset);

    // sub_1001B750
    int32_t isTypeCode83(int32_t idx);

    // sub_1001B780
    int32_t isMoreSlope(int32_t idx);

    // sub_1001B810
    CResultCaculator *setTickmarkStatus(int32_t status);

    // sub_1001BB50
    int32_t getIndex1Flag();

    // sub_1001BB70
    int32_t isBaseIdxGreatWithoutBaseTail();

    // sub_1001BBC0
    int32_t isBuff10HeightExceed();

    // sub_1001BDF0
    int32_t isEvSlopeX2GreatThenDH(int32_t idx);

    // sub_1001BE80
    int32_t isDTGreatThenBufferDT();

    // sub_1001BF80
    void clearTrHr();

    // sub_1001BFB0
    double calcSlopeAccordingFTime();

    // sub_1001C020
    int32_t isEvWidthX10GreatThenDT(int32_t idx);

    // sub_1001C0B0
    int32_t isBaseIdxGreatThenIndex1Head();

    // sub_1001C110
    int32_t getIndex2Flag();

    // sub_1001C130
    int32_t normalTrendNearEnd();

    // sub_1001C280
    int32_t checkTypeCode83AndIndex();

    // sub_1001C2D0
    int32_t isEvSlopeLitterThenDH();

    // sub_1001C350
    int32_t isHrGreatThenHalfOfFirst();

    // sub_1001C390
    int32_t isBuffer10HeightStandout();

    // sub_10007886
    int32_t checkBuffer10DeltaH(TDLLResultListItem *pHead);

    // sub_1001A7A0
    double getFirstHeadFTimeSpan();

    // sub_1000826C
    int32_t searchIndexAndCalcValue();

    // sub_1001B880
    int32_t isBuffer0TimeExceed();

    // sub_10007D60
    int32_t setPeakEndTypeNB(float time, float height, double area);

    // sub_10007A46
    int32_t setPeakAllTypeNB(int32_t time, float height, double area);

    // sub_1001C490
    int32_t isLocalDiffHExtruded8D();

    // sub_1001C580
    int32_t isLocalDiffHExtruded16D_();

    // sub_1000AD12
    int32_t isDriftExceedEventDrift(TDLLResultListItem *fp);

    // sub_1001C600
    CResultCaculator *setRawBag(int32_t *pRawBag);

    // sub_1001DB40
    int32_t setXMinUnitK(TMiscellaneous *wParam);
};
